package com.jxd.project.menu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jxd.project.menu.dto.MenuDTO;
import com.jxd.project.menu.dto.QueryMenuDTO;
import com.jxd.project.menu.model.Menu;
import com.jxd.project.menu.model.Role;
import com.jxd.project.menu.service.IMenuService;
import com.jxd.project.menu.service.IRoleService;
import com.jxd.project.menu.service.IRole_MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName MenuController
 * @Description TODO
 * @Author 刘成
 * @Date 2025/10/11 10:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/lc")
public class MenuController {
    @Autowired
    @Qualifier("menuServiceImpl")
    private IMenuService menuService;
    @Autowired
    @Qualifier("roleServiceImpl")
    private IRoleService roleService;
    @Autowired
    @Qualifier("role_MenuServiceImpl")
    private IRole_MenuService role_menuService;

    @RequestMapping("/getMenusWithDTO")
    public Map<String,Object> getMenusWithDTO(@RequestBody QueryMenuDTO queryMenuDTO){
        return menuService.getWithQueryMenuDTO(queryMenuDTO);
    }

    @RequestMapping("/addorEditMenu")
    public String addOrEditMenu(@RequestBody MenuDTO menuDTO){
        return menuService.addOrEditMenu(menuDTO) ? "success" : "fail";
    }

    @RequestMapping("/getSubMenu")
    public List<Menu> getSubMenu(int menuId){
        QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("frontmenu",menuId);
        return menuService.list(queryWrapper);
    }

    @RequestMapping("/delMenu")
    public String delMenu(int menuId){
        boolean flag = menuService.removeById(menuId) && role_menuService.delWithMenuId(menuId);
        return flag ? "success" : "fail";
    }

    @RequestMapping("/getOriginMenus")
    public List<Menu> getOriginMenus(){
        return menuService.getWithFrontMenus();
    }

    @RequestMapping("/getRole")
    public List<Role> getRole(){
        return roleService.list();
    }

    @RequestMapping("/getRoleWithMenuId")
    public List<Role> getRoleWithMenuId( int menuId){
        return roleService.getRoleWithMenuId(menuId);
    }

}
